/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chapter5;

/**
 *
 * @author Denise Carolina
 */
public class ExceptionsTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
//        doStuff();

        try {
            throw new Exception("try 1");
        }catch(Exception e){
            System.out.println("catch 1 " + e.getMessage());
            try{
                throw new Exception("try 2");
             }catch(Exception e1){
                System.out.println("catch 2 " + e1.getMessage());
             }finally{
                System.out.println("finally 2");
                try {
                    System.out.println("try 3");
                }finally{
                    System.out.println("finally 3");
                }
             }
        }finally{
            System.out.println("finally 1");
        }

        try {
            BadFoodException bf = new BadFoodException();
            bf.checkFood("pasta");
            bf.checkFood("fries");
            bf.checkFood("pasta");
        } catch (BadFoodException ex) {
            System.out.println("bad food:: " + ex);
        } finally{
            try{
                new BadFoodException().checkFood("pasta");
            }catch(BadFoodException exc){
                System.out.println("finally exception" + exc);
            }
        }
    }

    static void doStuff(){
        doMoreStuff();
    }

    static void doMoreStuff(){
        int x = 5/0;
    }
}

   class BadFoodException extends Exception{
        public void checkFood(String food) throws BadFoodException{
            if(food.equals("pasta")){

                System.out.println("!!!pasta!!!");
            }else{
                System.out.println("bad food in the method:: " + food);
                throw new BadFoodException();
            }
        }
   }
